# -*- coding:utf-8 -*-
import traceback

from utils.db_utils import DbConn
import datetime

from utils.logger import Md_Debug
from utils.serialization import Serialization
from app.project.common.project_sql import ProjectSql
from utils.backcode import ImportError


class ProjectEditDB(object):
    def __init__(self):
        self.serialization = Serialization()
    
    def del_project(self, body):
        """删除项目"""
        params = ['id']
        null_params = []
        sql = ProjectSql.DEL_PROJECT
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def del_project_member(self, body):
        """删除项目团队"""
        params = ['id']
        null_params = []
        sql = ProjectSql.DEL_PROJECT_GROUP
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def edit_project(self, body):
        """编辑项目"""
        params = ['name', 'leader', "status", "create_date", "plane_time", "end_date", "remarks","process", "id"]
        null_params = []
        sql = ProjectSql.EDIT_PROJECT
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def edit_project_member(self, body):
        """编辑项目团队"""
        params = ["object_id", "remarks", "user_id", "id"]
        null_params = ["object_id"]
        sql = ProjectSql.EDIT_PROJECT_GROUP
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def add_project(self, body):
        """添加项目"""
        params = ["name", "leader", "status", "create_date", "end_date", "plane_time", "remarks"]
        null_params = ["end_date", 'remarks']
        sql = ProjectSql.ADD_PROJECT
        ret = self.serialization.query_info(body, params, null_params, sql)
        return ret
    
    def project_over(self, body):
        params = ['name', 'leader', "status", "create_date", "plane_time", "end_date", "process", "id", "id", "id"]
        null_params = []
        sql = ProjectSql.OVER_PROJECT
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def add_project_member(self, body):
        """添加项目团队"""
        params = ["object_id", 'remarks', "session_user_id"]
        null_params = ["remarks"]
        sql = ProjectSql.ADD_PROJECT_GROUP
        ret = self.serialization.query_info(body, params, null_params, sql)
        return ret
    
    def project_member_edit_user(self, body):
        """修改项目团队成员"""
        params = ["project_group", "id"]
        null_params = []
        sql = ProjectSql.PROJECT_GROUP_EDIT_USER
        ret = self.serialization.query_info(body, params, null_params, sql)
        return ret
    
    def project_member_del_user(self, body):
        """删除项目团队成员"""
        params = ["user_id", "object_id", "user_id", "object_id"]
        null_params = []
        sql = ProjectSql.PROJECT_GROUP_DEL_USER
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def project_edit_leader(self, body):
        params = ["user_id", "project_id"]
        null_params = []
        sql = ProjectSql.PROJECT_EDIT_LEADER
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
